'/
' GUI Library
' Written by Anton Berlin, 2010.
' 
' =========================================================================
' 
' This program is free software; you can redistribute it and/or modify
' it under the terms of the GNU Lesser General Public License as published
' by the Free Software Foundation; either version 3 of the License.
' 
' This program is distributed in the hope that it will be useful,
' but WITHOUT ANY WARRANTY; without even the implied warranty of
' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
' GNU General Public License for more details.
' 
' You should have received a copy of the GNU Lesser General Public License
' along with this program; if not, write to the Free Software
' Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
'/

superstrict

import "GUI_Gadget.bmx"

type GUI_Window extends GUI_Gadget

	'// -------------------------------------------------------------------------------------------------------------
	'// Draw this gadget.
	'// -------------------------------------------------------------------------------------------------------------
	method draw()
	
		if (not m_visible) ..
			return;
		
		'// Setup the default drawing settings.
		drawutil.setColorInit(m_primitiveR, m_primitiveG, m_primitiveB);
		drawutil.setAlphaInit(m_transparency);
		drawutil.setFontInit(null);
		
		'// Draw the primitive of the gadget.
		drawRect(m_posX, m_posY, m_width, m_height);
		
		'// Draw the design of the gadget.
		design();
		
		'// Reset drawing settings.
		drawutil.resetColor();
		drawutil.resetAlpha();
		drawutil.resetFont();
	
	end method
	
	'// -------------------------------------------------------------------------------------------------------------
	'// Draw the design of this gadget.
	'// -------------------------------------------------------------------------------------------------------------
	method design()
	
		'// Shadow.
		if (m_useSurroundingShadows) ..
			drawSurroundingShadow();
		
		'// Border.
		setColor(m_primitiveR * 1.5, m_primitiveG * 1.5, m_primitiveB * 1.5);
		drawLine(m_posX, m_posY, m_posX + m_width, m_posY, false);
		drawLine(m_posX, m_posY, m_posX, m_posY + m_height, false);
		setColor(m_primitiveR * 0.5, m_primitiveG * 0.5, m_primitiveB * 0.5);
		drawLine(m_posX, m_posY + m_height, m_posX + m_width, m_posY + m_height, false);
		drawLine(m_posX + m_width, m_posY, m_posX + m_width, m_posY + m_height, false);
		
		'// Draw title.
		drawTitle();
	
	end method
	
	'// -------------------------------------------------------------------------------------------------------------
	'// Draw the title.
	'// -------------------------------------------------------------------------------------------------------------
	method drawTitle()
	
		if (not m_useTitle) ..
			return;
		
		'// Draw title bar.
		if (m_useTitleBar) then
		
			setColor(m_titleBarColorR, m_titleBarColorG, m_titleBarColorB);
			drawRect(m_posX + 3, m_posY + 3, m_width - 6, textHeight(m_titleText) + 2);
		
		end if
		
		'// Setup some stuff for drawing the title text.
		setImageFont(m_titleFont);
		
		local x:int;
		local y:int = m_posY + 4;
		
		if (m_centerTitleText) ..
			x = m_posX + m_width / 2 - textWidth(m_titleText) / 2; ..
		else ..
			x = m_posX + 6;
		
		'// Shadow.
		if (m_useShadows) then
		
			setAlpha(m_transparency * 0.5);
			setColor(0, 0, 0);
			drawText(m_titleText, x + 3, y + 3);
		
		end if
		
		if (m_useBorders) then
		
			'// Upper border.
			setAlpha(m_transparency * 1.0);
			setColor(m_titleFontColorR * 0.1, m_titleFontColorG * 0.1, m_titleFontColorB * 0.1)
			drawText(m_titleText, x, y);
			setAlpha(m_transparency * 1.0);
			setColor(m_titleFontColorR * 0.1, m_titleFontColorG * 0.1, m_titleFontColorB * 0.1)
			drawText(m_titleText, x, y + 1);
			setColor(m_titleFontColorR * 0.1, m_titleFontColorG * 0.1, m_titleFontColorB * 0.1)
			drawText(m_titleText, x + 1, y);
			
			'// Lower border.
			setColor(m_titleFontColorR * 0.1, m_titleFontColorG * 0.1, m_titleFontColorB * 0.1)
			drawText(m_titleText, x + 2, y + 2);
		
		end if
		
		'// Main title text.
		if (not m_useBorders) then
		
			setColor(m_titleFontColorR, m_titleFontColorG, m_titleFontColorB);
			drawText(m_titleText, x + 1, y);
			drawText(m_titleText, x + 2, y);
		
		else
		
			setColor(m_titleFontColorR, m_titleFontColorG, m_titleFontColorB);
			drawText(m_titleText, x + 1, y);
		
		end if
	
	end method
	
	'// -------------------------------------------------------------------------------------------------------------
	'// Set whether or not to use a window title.
	'// -------------------------------------------------------------------------------------------------------------
	method setTitleUsage(value:byte)
	
		m_useTitle = value;
	
	end method
	
	'// -------------------------------------------------------------------------------------------------------------
	'// Set whether or not to use a title bar.
	'// -------------------------------------------------------------------------------------------------------------
	method setTitleBarUsage(value:byte)
	
		m_useTitleBar = value;
	
	end method
	
	'// -------------------------------------------------------------------------------------------------------------
	'// Set whether or not to use shadows on the title text.
	'// -------------------------------------------------------------------------------------------------------------
	method setTitleShadowUsage(value:byte)
	
		m_useShadows = value;
	
	end method
	
	'// -------------------------------------------------------------------------------------------------------------
	'// Set whether or not to use borders on the title text.
	'// -------------------------------------------------------------------------------------------------------------
	method setTitleBorderUsage(value:byte)
	
		m_useBorders = value;
	
	end method
	
	'// -------------------------------------------------------------------------------------------------------------
	'// Set the window title.
	'// -------------------------------------------------------------------------------------------------------------
	method setTitle(str:string)
	
		m_titleText = str;
	
	end method
	
	'// -------------------------------------------------------------------------------------------------------------
	'// Set the color of the window title.
	'// -------------------------------------------------------------------------------------------------------------
	method setTitleColor(r:byte, g:byte, b:byte)
	
		m_titleFontColorR = r;
		m_titleFontColorG = g;
		m_titleFontColorB = b;
	
	end method
	
	'// -------------------------------------------------------------------------------------------------------------
	'// Set the color of the window bar.
	'// -------------------------------------------------------------------------------------------------------------
	method setTitleBarColor(r:byte, g:byte, b:byte)
	
		m_titleBarColorR = r;
		m_titleBarColorG = g;
		m_titleBarColorB = b;
	
	end method
	
	'// -------------------------------------------------------------------------------------------------------------
	'// Set the font of the window title.
	'// -------------------------------------------------------------------------------------------------------------
	method setTitleFont(font:TImageFont)
	
		m_titleFont = font;
	
	end method
	
	'// -------------------------------------------------------------------------------------------------------------
	'// Determines whether or not to use a window title.
	'// -------------------------------------------------------------------------------------------------------------
	field m_useTitle:byte = false;
	
	'// -------------------------------------------------------------------------------------------------------------
	'// The window title to use.
	'// -------------------------------------------------------------------------------------------------------------
	field m_titleText:string;
	
	'// -------------------------------------------------------------------------------------------------------------
	'// The font to use on the title text.
	'// -------------------------------------------------------------------------------------------------------------
	field m_titleFont:TImageFont;
	
	'// -------------------------------------------------------------------------------------------------------------
	'// Flag that determines whether or not to use a title bar.
	'// -------------------------------------------------------------------------------------------------------------
	field m_useTitleBar:byte = false;
	
	'// -------------------------------------------------------------------------------------------------------------
	'// Flag that determines whether or not to use shadows on the title text.
	'// -------------------------------------------------------------------------------------------------------------
	field m_useShadows:byte = false;
	
	'// -------------------------------------------------------------------------------------------------------------
	'// Flag that determines whether or not to use borders on the title text.
	'// -------------------------------------------------------------------------------------------------------------
	field m_useBorders:byte = false;
	
	'// -------------------------------------------------------------------------------------------------------------
	'// Flag that determines whether or not to center the title text.
	'// -------------------------------------------------------------------------------------------------------------
	field m_centerTitleText:byte = false;
	
	'// -------------------------------------------------------------------------------------------------------------
	'// Window title text color.
	'// -------------------------------------------------------------------------------------------------------------
	field m_titleFontColorR:byte;
	field m_titleFontColorG:byte;
	field m_titleFontColorB:byte;
	
	'// -------------------------------------------------------------------------------------------------------------
	'// Window title bar color.
	'// -------------------------------------------------------------------------------------------------------------
	field m_titleBarColorR:byte;
	field m_titleBarColorG:byte;
	field m_titleBarColorB:byte;

end type

